<?php

namespace app\admin\controller;

use think\Controller;
use app\common\model\ReplyModel;

class WechatController extends Controller
{
    /**
     * 公众号对接入口
     *@allow
     * @return void
     */
    public function index()
    {
        if(isset($_GET["echostr"])){ 
            $enc=$_REQUEST["echostr"];
            return $enc;
        }
        
        $data=file_get_contents('php://input');
        $res=simplexml_load_string($data,"SimpleXMLElement",LIBXML_NOCDATA);

        $reply=new ReplyModel();
        if($res->MsgType=="event"){
            $event=$res->Event;
            if($event=="subscribe"){
                return $reply->findFocus($res->FromUserName,$res->ToUserName);
            }else if($event=="unsubscribe"){
                //取消关注
                return "";
            } else if($event=="CLICK"){
                return $reply->findReply($res);
            }
            return "";
        }

        return $reply->findReply($res);
    }
}